home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / hash.h < prev    next >
C/C++ Source or Header  |  2001-06-08  |  1KB  |  54 lines

  1. /* Copyright (C) 2000 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: hash.h,v 1.9 2001/01/08 10:15:15 drscholl Exp $ */
  6.  
  7. #ifndef hash_h
  8. #define hash_h
  9.  
  10. #include <sys/types.h>
  11.  
  12. typedef void (*hash_destroy) (void *);
  13.  
  14. typedef unsigned int (*hash_key_t) (void *key);
  15. typedef int (*hash_compare_t) (void *, void *);
  16.  
  17. typedef struct _hashent
  18. {
  19.     void   *key;
  20.     void   *data;
  21.     struct _hashent *next;
  22. }
  23. HASHENT;
  24.  
  25. typedef struct _hash
  26. {
  27.     HASHENT **bucket;
  28.     int     numbuckets;
  29.     int     dbsize;        /* # of elements in the table */
  30.     hash_key_t hash_key;
  31.     hash_compare_t compare_key;
  32.     hash_destroy destroy;
  33. }
  34. HASH;
  35.  
  36. typedef void (*hash_callback_t) (void *, void *);
  37.  
  38. HASH   *hash_init (int, hash_destroy);
  39. int     hash_add (HASH *, void *key, void *);
  40. void   *hash_lookup (HASH *, void *key);
  41. int     hash_remove (HASH *, void *key);
  42. void    free_hash (HASH *);
  43. void    hash_foreach (HASH * h, hash_callback_t, void *funcdata);
  44. void    hash_set_hash_func (HASH * h, hash_key_t, hash_compare_t);
  45.  
  46. unsigned int   hash_pointer (void *key);
  47. unsigned int   hash_string (void *key);
  48. unsigned int   hash_u_int (void *key);
  49.  
  50. int     hash_compare_string (void *, void *);
  51. int     hash_compare_u_int (void *, void *);
  52.  
  53. #endif /* hash_h */
  54.